# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>
# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
pkgname=caprine
pkgver=2.60.1
pkgrel=2
pkgdesc="Elegant Facebook Messenger desktop app"
arch="x86_64 aarch64" # blocked by electron
url="https://github.com/sindresorhus/caprine"
license="MIT"
depends="electron"
makedepends="npm findutils coreutils"
options="!check" # No test suite
source="
	$pkgname-$pkgver.tar.gz::https://github.com/sindresorhus/caprine/archive/refs/tags/v$pkgver.tar.gz
	caprine.desktop
	caprine.sh
	"

build() {
	npm install --ignore-scripts
	npx --yes patch-package
	npx tsc
	rm -r node_modules
	npm install --ignore-scripts --production
	npx --yes patch-package
}

package() {
	local appdir=/usr/lib/caprine

	install -d "$pkgdir"$appdir
	cp -r ./* "$pkgdir"$appdir

	install -dm755 "$pkgdir/usr/share/pixmaps"
	install -m644 build/icon.png "$pkgdir/usr/share/pixmaps/$pkgname.png"

	install -Dm755 "$srcdir"/caprine.sh "$pkgdir"/usr/bin/caprine
	install -Dm644 "$srcdir"/caprine.desktop \
		"$pkgdir"/usr/share/applications/caprine.desktop

	install -dm755 "$pkgdir"/usr/share/licenses/caprine
	ln -s "$(realpath -m --relative-to=/usr/share/licenses/caprine $appdir/license)" \
		"$pkgdir"/usr/share/licenses/caprine

	# Clean up
	rm -r "$pkgdir"$appdir/build
	rm -r "$pkgdir"$appdir/source
	rm -r "$pkgdir"$appdir/tsconfig.json
	find "$pkgdir"$appdir \
		-name "package.json" \
			-exec sed -e "s|$srcdir/caprine|$appdir|" \
				-i {} \; \
		-or -name ".*" -prune -exec rm -r '{}' \; \
		-or -name "bin" -prune -exec rm -r '{}' \; \
		-or -name "example" -prune -exec rm -r '{}' \; \
		-or -name "examples" -prune -exec rm -r '{}' \; \
		-or -name "man" -prune -exec rm -r '{}' \; \
		-or -name "scripts" -prune -exec rm -r '{}' \; \
		-or -name "test" -prune -exec rm -r '{}' \;
}
sha512sums="
0df7f233c91f5a044dcffde94b976c6ad71e6d355518615c48cd825a249c01d63f455de31ece69193a66ca0fd8157506f9b88088da1bd47fc75e9d3800784ed0  caprine-2.60.1.tar.gz
a469e3bea24926119e51642b777ef794c5fa65421107903f967c36d81bbb1adb3d52469ce3a3301b2c890f1aa53ab989ded22a7c6e811fb8cf0a582dbd835e19  caprine.desktop
3ad8994c1a0417e73d622587769e527b4236a32c1a89442ff76413b75b4392d667c9e2908979b453e5926e54db6d94b31625340c5a94e84e91ea77f56feae778  caprine.sh
"
